package com.hs.jhzd.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hs.jhzd.entity.Task;
import com.hs.jhzd.service.task.TaskService;

@Controller
@RequestMapping("/task")
public class TaskController {
  @Autowired
  private TaskService taskService;

  @RequestMapping("/admin/main")
  public String shiftMainPage(Model model, String jsbh) {
    model.addAttribute("jsbh", jsbh);
    model.addAttribute("results", taskService.findAll());
    return "task-list";
  }

  @RequestMapping("/add")
  @ResponseBody
  public void addTask(Task task) {
    taskService.insert(task);
  }

  @RequestMapping("/delete")
  @ResponseBody
  public void addTask(@RequestParam(required = true) String id) {
    taskService.delete(id);
  }

  @RequestMapping("/findAll")
  @ResponseBody
  public List<Task> findallTask() {
    return taskService.findAll();
  }
}
